package net.csdn.business.discuss.api.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.csdn.business.discuss.api.model.dto.DiscussLikeDTO;
import net.csdn.business.discuss.api.model.entity.DiscussLikeRecord;
import net.csdn.business.discuss.api.model.query.BatchLikeRecordQuery;
import net.csdn.business.discuss.api.model.query.DiscussLikeRecordQuery;
import net.csdn.business.discuss.api.model.vo.DiscussLikeRecordVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 讨论点赞记录Mapper接口
 * 
 * @author zhangyl
 * @date 2023-07-25
 */
public interface DiscussLikeRecordMapper extends BaseMapper<DiscussLikeRecord>
{

    /**
     * 查询讨论投票记录
     * 
     * @param query 讨论投票记录主键
     * @return 讨论投票记录
     */
    @Select("select * from discuss_like_record where target_id=#{query.targetId} and target_type=#{query.targetType} and user_id=#{query.userId}")
    public DiscussLikeRecordVO selectDiscussVoteRecord(@Param("query") DiscussLikeDTO query);

    /**
     * 查询讨论投票记录列表
     * 
     * @param query 讨论投票记录
     * @return 讨论投票记录集合
     */
    @Select("select * from discuss_like_record where target_id=#{query.targetId} and target_type=#{query.targetType} and user_id=#{query.userId}")
    public List<DiscussLikeRecordVO> selectDiscussVoteRecordList(@Param("query") DiscussLikeDTO query);


    /**
     * 删除讨论投票记录
     * 
     * @param query 讨论投票记录
     * @return 结果
     */
    @Delete("delete from discuss_like_record where target_id=#{query.targetId} and target_type=#{query.targetType} and user_id=#{query.userId}")
    public Integer deleteDiscussLikeRecord(@Param("query") DiscussLikeDTO query);


    @Select({
            "<script>",
            "select target_id from discuss_like_record where  target_type=#{query.targetType} and user_id=#{query.userId} ",
            " and target_id in ",
            "<foreach collection='query.targetIds' item='targetId' open='(' separator=',' close=')' >",
            " #{targetId}",
            "</foreach>",
            "</script>"
    })
    public List<String> selectLikeRecordBatch(@Param("query") BatchLikeRecordQuery query);


    @Select("select * from discuss_like_record where target_id=#{query.targetId} and target_type=#{query.targetType} and user_id=#{query.userId}")
    public DiscussLikeRecordVO  selectLikeRecord(@Param("query") DiscussLikeRecordQuery query);

}
